package com.shardingdemo;

import com.shardingdemo.model.Order;
import com.shardingdemo.model.User;
import com.shardingdemo.service.OrderService;
import com.shardingdemo.service.User1Service;
import com.shardingdemo.service.UserService;
import com.shardingdemo.snowflake.IdUtils;
import org.apache.shardingsphere.api.hint.HintManager;
import org.apache.shardingsphere.shardingjdbc.jdbc.core.connection.ShardingConnection;
import org.apache.shardingsphere.shardingjdbc.jdbc.core.context.ShardingRuntimeContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.sql.DataSource;
import java.util.Random;

/**
 * @author chen_lei
 * @date 2020/7/21 21:03
 */
@RestController
public class UserController {
    @Autowired
    private UserService userService;
    @Autowired
    private DataSource dataSource;
    @Autowired
    private OrderService orderService;

    /**
     * 分库分表
     * @return
     */
    @GetMapping("/add")
    public Object add(){
        for (int i = 0; i < 100; i++) {
            String s = IdUtils.generateSnow();
            User user = new User();
            user.setUserId(s);
            user.setOrderId(0);
            int num = new Random().nextInt(5);
            user.setNum(num);
            boolean save = userService.save(user);
        }

        return "s";
    }

}
